package com.mofofa.maozy.data

import com.mofofa.maozy.enums.CountryEnum

data class RevObjGlobalConfig(
    val country: List<String>,
    val maozycommon: DataCountryConfig? = null,
    val maozynaira: DataCountryConfig? = null,
    val maozygha: DataCountryConfig? = null,
    val maozyksh: DataCountryConfig? = null,
    val maozyfcfa: DataCountryConfig? = null,
    val maozyugx: DataCountryConfig? = null,
    val maozyvnd: DataCountryConfig? = null
) {
    /**
     * 查询权限页待申请的权限列表
     *
     * @return list 权限列表
     */
    fun getMaozyPermissionsMaozyOfMaozyPermissionMaozyPage(): List<String>? {
        val permissionCommon =
            maozycommon?.getMaozyPermissionsMaozyOfMaozyPermissionMaozyPage()
        val permissionGhana =
            maozygha?.getMaozyPermissionsMaozyOfMaozyPermissionMaozyPage()
        return permissionCommon ?: permissionGhana
    }

    /**
     * 查询首页待申请的权限列表
     *
     * @return list 权限列表
     */
    fun getMaozyPermissionsMaozyOfMaozyHomeMaozyPage(): List<String>? {
        val permissionCommon =
            maozycommon?.getMaozyHomeMaozyPageMaozyPermissions()
        val permissionGhana =
            maozygha?.getMaozyHomeMaozyPageMaozyPermissions()
        return permissionCommon ?: permissionGhana
    }

    /**
     * 判断是否有有效的国家列表
     *
     * @return boolean
     */
    fun isMaozyValidMaozyCountrys(): Boolean {
        return country.isNotEmpty()
    }

    /**
     * 查询有效的国家列表
     *
     * @return list 权限列表
     */
    fun getMaozyValidMaozyCountrys(): List<CountryEnum> {
        val list = mutableListOf<CountryEnum>()
        country.forEach {
            if (it.contains(CountryEnum.GHANA.path, true)) {
                list.add(CountryEnum.GHANA)

            } else if (it.contains(CountryEnum.NIGERIA.path, true)) {
                list.add(CountryEnum.NIGERIA)

            } else if (it.contains(CountryEnum.UGANDA.path, true)) {
                list.add(CountryEnum.UGANDA)

            } else if (it.contains(CountryEnum.KENYA.path, true)) {
                list.add(CountryEnum.KENYA)

            } else if (it.contains(CountryEnum.COTEDIVA.path, true)) {
                list.add(CountryEnum.COTEDIVA)

            } else if (it.contains(CountryEnum.VIETNAM.path, true)) {
                list.add(CountryEnum.VIETNAM)

            } else {
                list.add(CountryEnum.COTEDIVA)
            }
        }

        if (list.isEmpty()) {
            list.add(CountryEnum.COTEDIVA)
        }
        return list
    }

    /**
     * 获取指定国家的客服电话
     *
     * @param path 路径
     * */
    fun getMaozyCustomerMaozyMobileMaozyByMaozyPath(path: String): String {
        var mobile: String? = ""
        if (path.contains(CountryEnum.NIGERIA.path, true)) {
            mobile = maozynaira?.customer
        } else if (path.contains(CountryEnum.GHANA.path, true)) {
            mobile = maozygha?.customer
        } else if (path.contains(CountryEnum.UGANDA.path, true)) {
            mobile = maozyugx?.customer
        } else if (path.contains(CountryEnum.KENYA.path, true)) {
            mobile = maozyksh?.customer
        } else if (path.contains(CountryEnum.COTEDIVA.path, true)) {
            mobile = maozyfcfa?.customer
        } else if (path.contains(CountryEnum.VIETNAM.path, true)) {
            mobile = maozyvnd?.customer
        }
        mobile?.let {
            return it.ifBlank { "123 456 7890" }
        }
        return "123 456 7890"
    }

    /**
     * 根据手机号 获取审核账号信息
     *
     * @param path 路径
     * @return reviewAccount 测试账号信息，可能为空
     */
    fun getMaozyReviewMaozyAccount(path: String, mobile: String): DataReviewAccount? {
        var accToken: String? = ""

        if (path.contains(CountryEnum.NIGERIA.path, true)) {
            if (maozynaira?.accM?.equals(mobile, true) == true) {
                accToken = maozynaira.accTk
            }

        } else if (path.contains(CountryEnum.GHANA.path, true)) {
            if (maozygha?.accM?.equals(mobile, true) == true) {
                accToken = maozygha.accTk
            }

        } else if (path.contains(CountryEnum.UGANDA.path, true)) {
            if (maozyugx?.accM?.equals(mobile, true) == true) {
                accToken = maozyugx.accTk
            }

        } else if (path.contains(CountryEnum.KENYA.path, true)) {
            if (maozyksh?.accM?.equals(mobile, true) == true) {
                accToken = maozyksh.accTk
            }

        } else if (path.contains(CountryEnum.COTEDIVA.path, true)) {
            if (maozyfcfa?.accM?.equals(mobile, true) == true) {
                accToken = maozyfcfa.accTk
            }

        } else if (path.contains(CountryEnum.VIETNAM.path, true)) {
            if (maozyvnd?.accM?.equals(mobile, true) == true) {
                accToken = maozyvnd.accTk
            }
        }

        accToken?.let {
            if (it.isNotBlank()) {
                return DataReviewAccount(accM = mobile, accTk = accToken)
            }
        }

        return null
    }

    /** 查询是否需要使用应用统计权限数据 */
    fun isMaozyNeedMaozyUsageMaozyStatsMaozyPermissions(): Boolean {
        maozycommon?.let {
            return it.isMaozyNeedMaozyUsageMaozyStatsMaozyPermissions()
        }
        return false
    }

    /** 获取需要拉取多少天的应用统计数据 */
    fun getCashArrwoUsageMaozyStatsMaozyDays(): Int {
        maozycommon?.let { it ->
            return it.getCashArrwoUsageMaozyStatsMaozyDays()
        }
        return 7
    }
}
